package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.UserMark;
import com.ssm.sfzy.mapper.UserMarkMapper;
import com.ssm.sfzy.service.UserMarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fuyanru
 * @date 2024年03月30日 15:56
 */
@Service
public class UserMarkServiceImpl implements UserMarkService {
    @Autowired
    private UserMarkMapper userMarkMapper;
    @Override
    public void add(UserMark entity) {
        userMarkMapper.insert(entity);
    }

    @Override
    public void edit(UserMark entity) {
        userMarkMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
      userMarkMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        userMarkMapper.deleteBatch(ids);
    }

    @Override
    public List<UserMark> find(UserMark entity) {
        return userMarkMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, UserMark entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserMark> list = userMarkMapper.select(entity);
        //
            PageInfo<UserMark> pageInfo = new PageInfo<>(list);
        // 整合处理
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public UserMark findById(Integer id) {
        return userMarkMapper.selectById(id);
    }
}
